<template>
  <div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="childOperation">
      <!-- 内容主体区域 -->
      <el-form :model="addForm" ref="addFormRef" label-width="70px">
        <el-form-item label="用户名">
          <el-input v-model="addForm.username" disabled></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="addForm.email"></el-input>
        </el-form-item>
        <el-form-item label="手机">
          <el-input v-model="addForm.mobile"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="childOperation">取 消</el-button>
        <el-button type="primary" @click="addOperation(addForm)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["showDigs", "ids"],
  data() {
    return {
      dialogVisible: false,
      addForm: {
        username: "",
        email: "",
        mobile: "",
      },
    };
  },
  created() {},
  watch: {
    showDigs: function (newval, oldval) {
      console.log(newval);
      this.dialogVisible = newval;
    },
    ids: function (newval) {
      this.$axios.get("/users/" + this.ids).then((res) => {
        this.addForm.username = res.data.data.username;
        this.addForm.email = res.data.data.email;
        this.addForm.mobile = res.data.data.mobile;
      });
    },
  },
  methods: {
    childOperation() {
      this.$emit("edit");
      this.dialogVisible = false;
    },
    addOperation(addForm) {
      this.$axios
        .put("/users/" + this.ids, {
          email: addForm.email,
          mobile: addForm.mobile,
        })
        .then((res) => {
          console.log(res);
          if (res.data.meta.status == 200) {
            this.$message({
              message: res.data.meta.msg,
              type: "success",
            });
            this.$emit("edit");
            this.dialogVisible = false;
            this.$emit("shuaxin");
          } else {
            this.$message({
              message: "更新失败",
              type: "error",
            });
          }
        });
    },
  },
};
</script>
<style lang='scss' scoped>
</style>